package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.utils.thread.WmUserThreadLocal;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author shiminghui
 * @date 2024/10/31 21:31
 * @description: TODO
 */
@RestController
@RequestMapping("api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        //获取用户信息
        WmUser user = WmUserThreadLocal.getUser();
        ResponseResult result = wmMaterialService.uploadPicture(multipartFile, user);
        return result;
    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto wmMaterialDto) {
        //获取用户信息
        WmUser user = WmUserThreadLocal.getUser();
        ResponseResult result = wmMaterialService.list(wmMaterialDto, user);
        return result;
    }

    @GetMapping("del_picture/{WmMaterialId}")
    public ResponseResult delPicture(@PathVariable("WmMaterialId") Integer WmMaterialId) {
        //获取用户信息
        WmUser user = WmUserThreadLocal.getUser();
        ResponseResult result = wmMaterialService.delPicture(WmMaterialId, user);
        return result;
    }

    @GetMapping("/collect/{WmMaterialId}")
    public ResponseResult collect(@PathVariable("WmMaterialId") Integer WmMaterialId) {
        //获取用户信息
        WmUser user = WmUserThreadLocal.getUser();
        return wmMaterialService.collect(WmMaterialId, user);
    }

    @GetMapping("/cancel_collect/{WmMaterialId}")
    public ResponseResult cancel_collect(@PathVariable("WmMaterialId") Integer WmMaterialId) {
        //获取用户信息
        WmUser user = WmUserThreadLocal.getUser();
        return wmMaterialService.collect(WmMaterialId, user);
    }

}
